package com.transitionseverywhere.utils;

import android.text.TextUtils;
import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.Method;

/* loaded from: classes.dex */
public class ReflectionUtils {
    private static final String TAG = ReflectionUtils.class.getSimpleName();
    private static final Object[] EMPTY_ARRAY = new Object[0];
    private static final Object[] ONE_OBJECT_ARRAY = new Object[1];
    private static final Object[] TWO_OBJECTS_ARRAY = new Object[2];
    private static final Object[] THREE_OBJECTS_ARRAY = new Object[3];
    private static final Object[] FOUR_OBJECTS_ARRAY = new Object[4];

    private ReflectionUtils() {
    }

    public static Class<?> getClass(String str) {
        try {
            return Class.forName(str);
        } catch (ClassNotFoundException unused) {
            return null;
        }
    }

    public static Method getMethod(Class<?> cls, String str, Class<?>... clsArr) {
        if (cls != null && !TextUtils.isEmpty(str)) {
            try {
                return cls.getMethod(str, clsArr);
            } catch (NoSuchMethodException | SecurityException unused) {
            }
        }
        return null;
    }

    public static Method getPrivateMethod(Class<?> cls, String str, Class<?>... clsArr) {
        if (cls != null && !TextUtils.isEmpty(str)) {
            try {
                Method declaredMethod = cls.getDeclaredMethod(str, clsArr);
                declaredMethod.setAccessible(true);
                return declaredMethod;
            } catch (NoSuchMethodException | SecurityException unused) {
            }
        }
        return null;
    }

    public static Object invoke(Object obj, Object obj2, Method method, Object... objArr) {
        if (method == null) {
            return obj2;
        }
        try {
            return method.invoke(obj, objArr);
        } catch (Exception e) {
            Log.e(TAG, "Exception in invoke", e);
            return obj2;
        }
    }

    public static Field getPrivateField(Class<?> cls, String str) {
        if (cls != null && !TextUtils.isEmpty(str)) {
            try {
                Field declaredField = cls.getDeclaredField(str);
                declaredField.setAccessible(true);
                return declaredField;
            } catch (NoSuchFieldException e) {
                e.printStackTrace();
            } catch (SecurityException e2) {
                e2.printStackTrace();
            }
        }
        return null;
    }

    public static void setFieldValue(Object obj, Field field, Object obj2) {
        if (field == null) {
            return;
        }
        try {
            field.set(obj, obj2);
        } catch (Exception e) {
            Log.e(TAG, "Exception in setFieldValue", e);
        }
    }

    public static Object getFieldValue(Object obj, Object obj2, Field field) {
        if (field == null) {
            return obj2;
        }
        try {
            return field.get(obj);
        } catch (Exception e) {
            Log.e(TAG, "Exception in getFieldValue", e);
            return obj2;
        }
    }

    public static Object invoke(Object obj, Object obj2, Method method) {
        return invoke(obj, obj2, method, EMPTY_ARRAY);
    }

    public static Object invoke(Object obj, Object obj2, Method method, Object obj3) {
        Object[] objArr = ONE_OBJECT_ARRAY;
        objArr[0] = obj3;
        Object invoke = invoke(obj, obj2, method, objArr);
        ONE_OBJECT_ARRAY[0] = null;
        return invoke;
    }

    public static Object invoke(Object obj, Object obj2, Method method, Object obj3, Object obj4) {
        Object[] objArr = TWO_OBJECTS_ARRAY;
        objArr[0] = obj3;
        objArr[1] = obj4;
        Object invoke = invoke(obj, obj2, method, objArr);
        Object[] objArr2 = TWO_OBJECTS_ARRAY;
        objArr2[0] = null;
        objArr2[1] = null;
        return invoke;
    }

    public static Object invoke(Object obj, Object obj2, Method method, Object obj3, Object obj4, Object obj5) {
        Object[] objArr = THREE_OBJECTS_ARRAY;
        objArr[0] = obj3;
        objArr[1] = obj4;
        objArr[2] = obj5;
        Object invoke = invoke(obj, obj2, method, objArr);
        Object[] objArr2 = THREE_OBJECTS_ARRAY;
        objArr2[0] = null;
        objArr2[1] = null;
        objArr2[2] = null;
        return invoke;
    }

    public static Object invoke(Object obj, Object obj2, Method method, Object obj3, Object obj4, Object obj5, Object obj6) {
        Object[] objArr = FOUR_OBJECTS_ARRAY;
        objArr[0] = obj3;
        objArr[1] = obj4;
        objArr[2] = obj5;
        objArr[3] = obj6;
        Object invoke = invoke(obj, obj2, method, objArr);
        Object[] objArr2 = FOUR_OBJECTS_ARRAY;
        objArr2[0] = null;
        objArr2[1] = null;
        objArr2[2] = null;
        objArr2[3] = null;
        return invoke;
    }
}
